package zzps.exeed.kernel.convert.impl;

import zzps.exeed.kernel.convert.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<Date> {
    private final Class<? extends java.util.Date> targetType;

    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public DateConverter(Class<? extends Date> targetType) {
        this.targetType = targetType;
    }

    @Override
    public Date convert(Object value) {
        if (value instanceof Date){
            return (Date) value;
        }
        String str = toStr(value);
        try {
            Date date = dateFormat.parse(str);
            return date;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
